package org.lansir.viewpager;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;

public class ViewPagerTestActivity extends Activity {
    /** Called when the activity is first created. */
	private LanViewPager mViewPager;
	
	private View view1;
	private View view2;
	private List<View> mListViews;
	TitleFlowIndicator indic;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LayoutInflater mInflater = this.getLayoutInflater();
        mViewPager = (LanViewPager)findViewById(R.id.viewpager);
        mListViews = new ArrayList<View>();
        mListViews.add((view1=mInflater.inflate(R.layout.view1, null)));
        mListViews.add((view2=mInflater.inflate(R.layout.view2, null)));
        mListViews.add((view2=mInflater.inflate(R.layout.view2, null)));
        ViewPagerAdapter adapter = new ViewPagerAdapter();
        mViewPager.setAdapter(adapter);
        indic = (TitleFlowIndicator) findViewById(R.id.viewflowindic);
        mViewPager.setIndicator(indic);
        indic.setTitleProvider(adapter);
       
   }
    
    private class ViewPagerAdapter extends PagerAdapter implements TitleProvider{

		@Override
		public void destroyItem(View collection, int position, Object view) {
			
			((ViewPager)collection).removeView(mListViews.get(position));
			
		}

		@Override
		public void finishUpdate(View arg0) {
			
		}

		@Override
		public int getCount() {
			return mListViews.size();
		}

		@Override
		public Object instantiateItem(View collection, int position) {
			
			((ViewPager)collection).addView(mListViews.get(position), 0);
			return mListViews.get(position);
		}

		@Override
		public boolean isViewFromObject(View view, Object object) {

			return view == object;
		}

		@Override
		public void restoreState(Parcelable arg0, ClassLoader arg1) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public Parcelable saveState() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void startUpdate(View arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public String getTitle(int position) {
			
			return "Hello";
		}
    	
    };
}